<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js表达式</title>
</head>
<body>
    <div id="app">
        <h3 v-my-text="{name:'肖雅涵',color:'blue'}"></h3>
        <h3 v-my-text="{name:'Terrors',color:'red'}"></h3>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
    <script type="text/javascript">
        new Vue({
            el:'#app',
            data: {
                msg:'在上海学习'
            },
            directives:{
                'my-text' (el,binding){
                    console.log(el,binding);
                    //设置文本 和颜色
                    el.innerHTML=binding.value.name;
                    el.style.backgroundColor=binding.value.color;
                }
            }
        })
    </script>
</body>
</html>